<template>
  <div class="treat-reviewed-box">
    <el-card class="header-card-box">
      <div class="header">
        <Describe :describe="values" />
        <div class="action">
          <span>
            <el-button type="primary"
                       @click="handerReviewedPass">审核关闭通过</el-button>
          </span>
          <span>
            <el-button type="primary"
                       @click="handerBargaRefuse">审核关闭拒绝</el-button>
          </span>
          <span class="cancel">
            <el-button plain
                       @click="cancel">取消</el-button>
          </span>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
import axios from 'axios'
import Describe from './Describe.vue'

export default {
  name: 'TreatReviewedHeader',
  components: { Describe },
  props: {
    value: {
      type: Object,
      default: () => { }
    }
  },
  data () {
    return {

    }
  },
  computed: {
    values () {
      return this.value
    }
  },
  created () {
    console.log('templateId', this.values)
  },
  methods: {
    handerReviewedPass () {
      this.$confirm('是否继续该操作?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.getReviewedPass()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    handerBargaRefuse () {
      this.$prompt("", '拒绝合约关闭原因', {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputType: "textarea",
        inputPattern: /^.{1,200}$/,
        inputPlaceholder: `请输入合约关闭原因`,
        inputErrorMessage: `合约关闭原因原因不能为空,且不能超过200个字符`
      })
        .then(({ value }) => {
          let data = { reason: value, templateId: this.values?.templateId }
          this.getCloseReject(data)
        })
        .catch(() => { });
    },
    cancel () {
      this.$router.go(-1)
    },
    async getReviewedPass () {
      let url = `/quotation/template/close/agree`
      let response = await axios.put(url, { templateId: this.values?.templateId })
      console.log('response', response)
      // this.$message({
      //   type: 'success',
      //   message: '操作成功'
      // });
      // this.cancel()
      if (response.code === 0) {
        this.$message({
          type: 'success',
          message: '操作成功'
        });
        this.cancel()
      }
    },
    async getCloseReject (params) {
      let url = `/quotation/template/close/reject`
      let response = await axios.put(url, params)
      console.log('response', response)
      this.$message({
        type: 'success',
        message: '操作成功'
      });
      this.cancel()
      // if (code === 0) {
      //   this.$message({
      //     type: 'success',
      //     message: message
      //   });
      //   this.cancel()
      // }
    }
  },
}
</script>

<style scoped>
.header {
  height: 32px;
  line-height: 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.btn-dropdown {
  /* padding: 0 10px; */
  padding-left: 10px;
}
.cancel {
  padding-left: 10px;
}
.action {
  /* display: flex; */
  width: 30%;
  text-align: end;
}
.action span {
  padding-left: 10px;
}
</style>